package com.mycms.module.common.controller;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

@Controller
public class AlertController {
	
	@Autowired
	private MessageSource messageSource;
	
	@RequestMapping(value="/alert.do", method = RequestMethod.GET)	
	public void alert(HttpServletRequest request, HttpServletResponse response, HttpSession session, @RequestParam String msg, Locale locale) {
		try {			
			response.setContentType("text/html;charset=UTF-8");
			response.getWriter().write("<script>");
			response.getWriter().write("alert('"+messageSource.getMessage("alert."+msg, null, "Korean", locale)+"');");
			response.getWriter().write("document.location.href='" + request.getHeader("referer") + "'");
			response.getWriter().write("</script>");
		} catch (IOException e) {			
			e.printStackTrace();
		}
	}
}
